const express = require("express");
const router = express.Router();

const likeModel = require("../../model/likeModel");

//点赞
router.post("/addlike", (req, res) => {
    let { user_id, news_id } = req.body;
    likeModel
        .addLike({ user_id, news_id })
        .then((data) => {
            res.send(data);
        })
        .catch((err) => {
            res.send(err);
        });
});
//取消点赞
router.post("/removelike", (req, res) => {
    let { user_id, news_id } = req.body;
    likeModel
        .removelike({ user_id, news_id })
        .then((data) => {
            res.send(data);
        })
        .catch((err) => {
            res.send(err);
        });
});
//获取点赞数量
router.get("/likecount", (req, res) => {
    let { news_id } = req.query;
    likeModel
        .getLikeCount({ news_id })
        .then((data) => {
            res.send(data);
        })
        .catch((err) => {
            res.send(err);
        });
});

//获取点赞列表
router.get("/getlike", (req, res) => {
    let { user_id, news_id } = req.query;
    likeModel
        .getLikeList({ user_id, news_id })
        .then((data) => {
            res.send({
                code: 200,
                msg: "获取点赞列表成功",
                data,
            });
        })
        .catch((err) => {
            res.send({
                code: -1,
                msg: "获取点赞列表失败",
                err,
            });
        });
});

module.exports = router;
